<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\QuizItem;
use App\Models\Quiz;
use App\Http\Requests\PlayRequest;
use App\Http\Requests\AnnounceRequest;
use App\Repositories\QuizRepository;


/**
 * @resource 竞猜操作
 * Class PlayController
 * @package App\Http\Controllers\Api
 */
class PlayController extends Controller
{

    /**
     * 下注
     *
     * @param QuizItem $quizItem
     * @param PlayRequest $request
     * @param QuizRepository $quizRepository
     */
    public function bet(QuizItem $quizItem, PlayRequest $request,
                        QuizRepository $quizRepository)
    {
        $quizRepository->bet($quizItem, $request->copper);
    }


    /**
     * 公布结果
     *
     * @param Quiz $quiz
     * @param AnnounceRequest $request
     * @param QuizRepository $quizRepository
     */
    public function announce(Quiz $quiz, AnnounceRequest $request,
                             QuizRepository $quizRepository)
    {
        $quizRepository->announce($quiz, $request);
        $quiz->removeCache();
    }
}
